package com.lzh.service.adapter;

import com.lzh.domain.entity.User;
import com.lzh.webSocket.domain.vo.resp.WSBaseResp;
import com.lzh.webSocket.domain.vo.resp.WSRespTypeEnum;
import com.lzh.webSocket.domain.vo.ws.WSLoginSuccess;
import com.lzh.webSocket.domain.vo.ws.WSLoginUrl;
import org.springframework.stereotype.Component;


@Component
public class WSAdapter {
    //@Autowired
    //private ChatService chatService;

    public static WSBaseResp<WSLoginUrl> buildLoginResp(String  url) {
        WSBaseResp<WSLoginUrl> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_URL.getType());
        wsBaseResp.setData(WSLoginUrl.builder().loginUrl(url).build());
        return wsBaseResp;
    }


    public static WSBaseResp<WSLoginSuccess> buildLoginSuccessMessageResp(User user,String token,Boolean isAdmin) {
        WSBaseResp<WSLoginSuccess> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.LOGIN_SUCCESS.getType());
        WSLoginSuccess loginInfo = WSLoginSuccess.builder()
                .avatar(user.getAvatar())
                .name(user.getName())
                .power(isAdmin?1:0)
                .token(token)
                .uid(user.getId())
                .build();
        wsBaseResp.setData(loginInfo);
        return wsBaseResp;
    }


    public static WSBaseResp<WSLoginSuccess> againLogin() {
        WSBaseResp<WSLoginSuccess> wsBaseResp = new WSBaseResp<>();
        wsBaseResp.setType(WSRespTypeEnum.INVALIDATE_TOKEN.getType());
        return wsBaseResp;
    }




}
